package model;

import java.io.Serializable;
import java.util.List;
import java.util.GregorianCalendar;
import java.util.LinkedList;

public abstract class Document implements Serializable {
	private static final long serialVersionUID = 1L;
	private static short maxID = 0;
	private short id;
	private String category;
	private short year;
	private String title;
	private List<String> authors;
	private String editor;
	private GregorianCalendar dateBorrow;
	private GregorianCalendar dateAvaillable;
	private GregorianCalendar date1stReserve;
	private User borrowBy = null;
	private LinkedList<User> listReserve = new LinkedList<User>();
	
	public Document(String category, short year, String title, List<String> authors, String editor) {
		this.id = Document.maxID++;
		this.category = category;
		this.year = year;
		this.authors = authors;
		this.title = title;
		this.editor = editor;
		this.dateBorrow = null;
		this.dateAvaillable = null;
	}
	
	public boolean isBorrowable(User user) {
		if(this.dateBorrow == null && (this.listReserve.isEmpty() || this.listReserve.peek().equals(user))) {
			return true;
		}
		return false;
	}
	
	public short getID() {
		return this.id;
	}
	
	public String getTitle() {
		return this.title;
	}
	
	public short getYear() {
		return this.year;
	}
	
	public String getCategory() {
		return this.category;
	}

	/**
	 * @return the id
	 */
	public short getId() {
		return this.id;
	}

	/**
	 * @return the authors
	 */
	public List<String> getAuthors() {
		return this.authors;
	}

	/**
	 * @return the editor
	 */
	public String getEditor() {
		return this.editor;
	}

	/**
	 * @param category the category to set
	 */
	public void setCategory(String category) {
		this.category = category;
	}

	/**
	 * @param year the year to set
	 */
	public void setYear(short year) {
		this.year = year;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @param authors the authors to set
	 */
	public void setAuthors(List<String> authors) {
		this.authors = authors;
	}

	/**
	 * @param editor the editor to set
	 */
	public void setEditor(String editor) {
		this.editor = editor;
	}

	/**
	 * @return the dateBorrow
	 */
	public GregorianCalendar getDateBorrow() {
		return dateBorrow;
	}

	/**
	 * @param dateBorrow the dateBorrow to set
	 */
	public void setDateBorrow(GregorianCalendar dateBorrow) {
		this.dateBorrow = dateBorrow;
	}

	/**
	 * @return the dateAvaillable
	 */
	public GregorianCalendar getDateAvaillable() {
		return dateAvaillable;
	}

	/**
	 * @param dateAvaillable the dateAvaillable to set
	 */
	public void setDateAvaillable(GregorianCalendar dateAvaillable) {
		this.dateAvaillable = dateAvaillable;
	}

	/**
	 * @return the listReserve
	 */
	public LinkedList<User> getListReserve() {
		return listReserve;
	}

	/**
	 * @return the borrowBy
	 */
	public User getBorrowBy() {
		return borrowBy;
	}

	/**
	 * @param borrowBy the borrowBy to set
	 */
	public void setBorrowBy(User borrowBy) {
		this.borrowBy = borrowBy;
	}

	/**
	 * @return the date1stReserve
	 */
	public GregorianCalendar getDate1stReserve() {
		return date1stReserve;
	}

	/**
	 * @param date1stReserve the date1stReserve to set
	 */
	public void setDate1stReserve(GregorianCalendar date1stReserve) {
		this.date1stReserve = date1stReserve;
	}
}
